home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue34 / timetrav / testmain.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1998-03-25  |  5.4 KB  |  205 lines

  1. unit testmain;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, BaseDate, ComCtrls, Buttons, ExtCtrls, Grids, Calendar, ModCal;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     E_MJD: TEdit;
  12.     E_year: TEdit;
  13.     E_month: TEdit;
  14.     E_day: TEdit;
  15.     Label1: TLabel;
  16.     Label2: TLabel;
  17.     Label3: TLabel;
  18.     YMDToDateTime: TBitBtn;
  19.     b_ymdToMJD: TBitBtn;
  20.     BitBtn3: TBitBtn;
  21.     b_DTtoMJD: TBitBtn;
  22.     b_mjdtoymd: TBitBtn;
  23.     UpDown1: TUpDown;
  24.     UpDown2: TUpDown;
  25.     Label5: TLabel;
  26.     Label6: TLabel;
  27.     Label7: TLabel;
  28.     Label8: TLabel;
  29.     y2: TEdit;
  30.     m2: TEdit;
  31.     d2: TEdit;
  32.     UpDown3: TUpDown;
  33.     UpDown4: TUpDown;
  34.     Label9: TLabel;
  35.     e_MJD2: TEdit;
  36.     bMJD2toYMD: TBitBtn;
  37.     Panel1: TPanel;
  38.     Label4: TLabel;
  39.     Memo1: TMemo;
  40.     DateTimePicker1: TDateTimePicker;
  41.     bRollup: TBitBtn;
  42.     Calendar1: TCalendar;
  43.     b_MSDateToCal: TBitBtn;
  44.     L_cal1Month: TLabel;
  45.     L_cal1year: TLabel;
  46.     b_MJDToCal: TBitBtn;
  47.     L_MJDCalMonth: TLabel;
  48.     L_MJDCalYear: TLabel;
  49.     procedure FormCreate(Sender: TObject);
  50.     procedure Button1Click(Sender: TObject);
  51.     procedure Button2Click(Sender: TObject);
  52.     procedure YMDToDateTimeClick(Sender: TObject);
  53.     procedure BitBtn2Click(Sender: TObject);
  54.     procedure b_DTtoMJDClick(Sender: TObject);
  55.     procedure BitBtn3Click(Sender: TObject);
  56.     procedure b_mjdtoymdClick(Sender: TObject);
  57.     procedure bRollupClick(Sender: TObject);
  58.     procedure b_ymdToMJDClick(Sender: TObject);
  59.     procedure b_MSDateToCalClick(Sender: TObject);
  60.     procedure b_MJDToCalClick(Sender: TObject);
  61.   private
  62.     EnglishCalendar : tEnglishCalendar;
  63.     TestCal : tModCal;
  64.   public
  65.     { Public declarations }
  66.   end;
  67.  
  68. var
  69.   Form1: TForm1;
  70.  
  71. implementation
  72.  
  73. {$R *.DFM}
  74.  
  75. procedure TForm1.FormCreate(Sender: TObject);
  76. begin
  77.   EnglishCalendar := TEnglishCalendar.create;
  78.   TestCal := TModcal.create(self);
  79.   with TestCal do begin
  80.     left := 6;
  81.     top := Calendar1.top;
  82.     parent := self;
  83.     end;
  84. end;
  85.  
  86. procedure TForm1.Button1Click(Sender: TObject);
  87. var test : tdatetime;
  88. begin
  89.   test := EnglishCalendar.MSDatefromMJD(strToInt(e_mjd.text));
  90.   memo1.lines.add('raw tdatetime = '+ floattostr(test));
  91.  
  92.   memo1.lines.add('date is '+ FormatDateTime('dd mmm yyyy', test));
  93. end;
  94.  
  95. procedure TForm1.Button2Click(Sender: TObject);
  96. var test : tMJD;
  97. begin
  98.   test := EnglishCalendar.MJDfromMSDate(strToInt(e_mjd.text));
  99.   memo1.lines.add('raw MJD = '+ floattostr(test));
  100. end;
  101.  
  102. procedure TForm1.YMDToDateTimeClick(Sender: TObject);
  103. begin
  104.   with DateTimePicker1 do begin
  105.     date := encodedate(StrToInt(e_Year.text), StrToInt(e_Month.text), StrToInt(e_Day.text));
  106.     application.ProcessMessages;
  107.     invalidate;
  108.     with memo1.lines do begin
  109.       clear;
  110.       add('sent YMD ('+e_year.text+' '+e_month.text+' '+e_day.text+') to DateTimePicker');
  111.       add('raw tdatetime = '+ floattostr(date));
  112.       add('date is '+ FormatDateTime('dd mmm yyyy', date));
  113.       add('weekday is '+FormatDateTime('dddd',date));
  114.       end;
  115.     end;
  116.  
  117. end;
  118.  
  119. procedure TForm1.BitBtn2Click(Sender: TObject);
  120. var CalendarDate : tCalendarDate;
  121. begin
  122.   CalendarDate := EnglishCalendar.DecodeDate(StrToInt(e_MJD2.text));
  123.   with CalendarDate do begin
  124.     y2.text := IntToStr(year);
  125.     m2.text := IntToStr(Month);
  126.     d2.text := IntToStr(day);
  127.     end;
  128. end;
  129.  
  130. procedure TForm1.b_DTtoMJDClick(Sender: TObject);
  131. var test : tMJD;
  132. begin
  133.   test := EnglishCalendar.MJDfromMSDate(DateTimePicker1.date);
  134.   e_mjd2.text := floatToStr(test);
  135. end;
  136.  
  137. procedure TForm1.BitBtn3Click(Sender: TObject);
  138. begin
  139.   with DateTimePicker1 do begin
  140.     date := EnglishCalendar.MSDatefromMJD(strToInt(e_mjd.text));
  141.     invalidate;
  142.     with memo1.lines do begin
  143.       clear;
  144.       add('sent MJD '+e_mjd.text+ ' to DateTimePicker');
  145.       add('raw tdatetime = '+ floattostr(date));
  146.       add('date is '+ FormatDateTime('dd mmm yyyy', date));
  147.       add('weekday is '+FormatDateTime('dddd',date));
  148.       end;
  149.     end;
  150. end;
  151.  
  152. procedure TForm1.b_mjdtoymdClick(Sender: TObject);
  153. var CalendarDate : tCalendarDate;
  154. begin
  155.   CalendarDate := EnglishCalendar.DecodeDate(StrToInt(e_MJD.text));
  156.   with CalendarDate do begin
  157.     y2.text := IntToStr(year);
  158.     m2.text := IntToStr(Month);
  159.     d2.text := IntToStr(day);
  160.     end;
  161.  
  162. end;
  163.  
  164. procedure TForm1.bRollupClick(Sender: TObject);
  165. begin
  166.   e_year.text :=  y2.Text;
  167.   e_month.text := m2.text;
  168.   e_day.text := d2.text;
  169. end;
  170.  
  171. procedure TForm1.b_ymdToMJDClick(Sender: TObject);
  172. var MJD : tmjd;
  173. begin
  174.   MJD := EnglishCalendar.EncodeDate(StrToInt(e_Year.text), StrToInt(e_Month.text), StrToInt(e_Day.text));
  175.   e_MJD.text := IntToStr(trunc(MJD));
  176. end;
  177.  
  178. procedure TForm1.b_MSDateToCalClick(Sender: TObject);
  179. var ayear, amonth, aday : word;
  180. begin
  181.   with Calendar1 do begin
  182.     DecodeDate(DateTimePicker1.date, ayear, amonth, aday);
  183.     year := ayear;
  184.     month := amonth;
  185.     day := aday;
  186.     l_cal1month.caption := LongMonthNames[month];
  187.     l_cal1Year.caption := IntToStr(year);
  188.     end;
  189. end;
  190.  
  191. procedure TForm1.b_MJDToCalClick(Sender: TObject);
  192. var YMD : TCalendarDate;
  193. begin
  194.   with TestCal do begin
  195.     YMD := EnglishCalendar.DecodeDate(StrToInt(e_MJD.text));
  196.     year := YMD.year;
  197.     month := YMD.month;
  198.     day := YMD.Day;
  199.     l_MJDCalmonth.caption := EnglishCalendar.Yeardef.MonthName[month];
  200.     l_MJDCalYear.caption := IntToStr(year);
  201.     end;
  202. end;
  203.  
  204. end.
  205.